package com.fang.study_demo01.controller;

import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Bernie_xin
 * @create 2020/12/3 21:41
 **/
@Controller
@RequestMapping("/test")
public class Hello {

    @GetMapping("/hello")
    public String hello() {
        return "Hello Security";
    }

    @GetMapping("/indexs")
    public String index() {
        return "index";
    }

    @GetMapping("/toLogin")
    public String tologin() {
        return "login";
    }

    @GetMapping("/fail")
    public String fail() {
        return "Login fail";
    }

    @GetMapping("/hello2")
    public String hello2() {
        return "Hello22222 Security";
    }

    @GetMapping("/update")
    @ResponseBody
    // @Secured({"ROLE_sale","ROLE_manager","ROLE_admin"})

    @PreAuthorize("hasAnyAuthority('admin')")
    //@PreAuthorize("hasRole('ROLE_admin')")
    public String update() {
        return "Hello update";
    }

}
